package chapter7;

import java.io.IOException;

import javax.servlet.RequestDispatcher;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

@WebServlet("/modifyCustomer")
public class ModifyCustomerServlet extends HttpServlet {
	@Override
	protected void doGet(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {
		request.setCharacterEncoding("utf-8");
		response.setContentType("text/html;charset=utf-8");
		
		String custId = request.getParameter("cust_id");
		String cname = request.getParameter("cname");
		String email = request.getParameter("email");
		String balance = request.getParameter("balance");
		
		Customer customer = new Customer();
		customer.setCust_id(custId);
		customer.setCname(cname);
		customer.setEmail(email);
		customer.setBalance(Double.parseDouble(balance));
		
		CustomerDao customerDao = new CustomerDao();
		int rst = customerDao.modifyCustomer(customer);
		
		String message = null;
		if (rst == 1) {
			message = "<li>成功修改一条记录！</li>";
		} else {
			message = "<li>修改记录错误！</li>";
		}
		
		request.setAttribute("result", message);
		
		RequestDispatcher rd = getServletContext().getRequestDispatcher(
				"/showCustomers");
		rd.forward(request, response);
		
		
		
		
		
	}
}
